import FileSaver from "file-saver";
import XLSX from "xlsx";
import $ from 'jquery'
export default {
  go_alert: function (msg) {
    $("body").append(`
    <div class='alert_box' style='position:fixed;z-index:8889;width:100%;height:100%;left:0;top:0px;background: rgba(255, 255, 255, 0)'>
      <div class='content' style='max-width: 70%;text-align:center;position:absolute;font-size:14px;left:50%;top:50%; transform:translateY(-50%) translateX(-50%);-webkit-transform:translateY(-50%) translateX(-50%);background-color:rgba(0,0,0,.5);border-radius:4px'>
        <p style='padding:10px 15px; line-height:1.6; color:#fff;font-size:14px'>${msg}</p>
      <div>
    <div>`);
    setTimeout(function () {
      $(".alert_box").css({ "opacity": "0", "width": "0%", "height": "0" })
      setTimeout(function () { $(".alert_box").remove() }, 2000);
    }, 2000)

  },
  enlargeImg: function (ImgUrl) {

    let imgurl = ImgUrl ? `<img style="max-width:100%;" src="${ImgUrl}"/>` : '';
    let template = `<div class="enlargeImg"
		style="position: fixed;z-index: 1000;
		width: 100%;opacity: 1;height: 100%;left: 0;
		top: 0px;background-color: rgba(68, 68, 68, 0.7)">
   <div style="width:100%;height:100%;overflow-y: auto;display:flex;align-items:center;-webkit-align-items: center;
   justify-content: center;-webkit-justify-content: center;"
   ">
   	${imgurl}
	  </div>
   </div>`
    $("body").append(template)
    $(".enlargeImg").click(function () {
      var that = $(this);
      setTimeout(function () {
        // 隐藏弹框
        that.css({ "opacity": "0", "width": "0%", "height": "0" });
        setTimeout(function () { that.remove() }, 0);
      }, 0)
    })
  },
  loading: function () {
    $("body").append(`<div class='loading_box' style='position:fixed;z-index:1500;width:100%;opacity:1;height:100%;left:0;top:0px;background-color:transparent;'>
    <div class='content' style='max-width: 70%;text-align:center;position:absolute;font-size:14px;left:50%;top:50%; transform:translateY(-50%) translateX(-50%);-webkit-transform:translateY(-50%) translateX(-50%);border-radius:4px'>
    <img style='width: 40px' src='../static/img/slice/loading.gif' />
    <div>
    <div>`);
  },
  loadingHide: function () {
    if ($(".loading_box").length) {
      $(".loading_box").remove();
    }
  },
  // 格式化时间 ,displaytime 是否显示具体时间，1为显示，2为显示不显示秒，0为不显示
  dateFormat: function (item, displaytime) {
    if (item) {


      let date = new Date(item * 1000);
      let year = date.getFullYear()
      let month = date.getMonth() + 1
      let day = date.getDate()
      let hour = date.getHours()
      let minute = date.getMinutes()
      let second = date.getSeconds()

      let str = `${year}-${month > 9 ? month : `0${month}`}-${day > 9 ? day : `0${day}`}`;
      if (displaytime == 1) {
        str = str + ` ${hour > 9 ? hour : `0${hour}`}:${minute > 9 ? minute : `0${minute}`}:${second > 9 ? second : `0${second}`}`
      } else if (displaytime == 2) {
        str = str + ` ${hour > 9 ? hour : `0${hour}`}:${minute > 9 ? minute : `0${minute}`}`
      }
      return str;
    }
  },
  // 获取当前日期
  // displaytime 是否显示具体时间，1为显示，2为显示不显示秒，0为不显示
  dateFormatStr: function (date, displaytime, lianjiefu) {
    let strDate = new Date(date);
    let year = strDate.getFullYear()
    let month = strDate.getMonth() + 1
    let day = strDate.getDate()
    let hour = strDate.getHours()
    let minute = strDate.getMinutes()
    let second = strDate.getSeconds()
    if (lianjiefu == undefined) {
      lianjiefu = "-";
    }
    let str = `${year}${lianjiefu}${month > 9 ? month : `0${month}`}${lianjiefu}${day > 9 ? day : `0${day}`}`;
    if (displaytime == 1) {
      str = str + ` ${hour > 9 ? hour : `0${hour}`}:${minute > 9 ? minute : `0${minute}`}:${second > 9 ? second : `0${second}`}`
    } else if (displaytime == 2) {
      str = str + ` ${hour > 9 ? hour : `0${hour}`}:${minute > 9 ? minute : `0${minute}`}`
    }
    return str;
  },
  // 截取字符串指定长度
  spliceLabel: function (val, leng) {
    return val.length > leng ? val.slice(0, leng) + "..." : val;
  },
  storageObj: function (obj) {
    var Str = JSON.stringify(obj);
    sessionStorage.setItem("userInfo", Str);
  },
  // 导出表格-全部导出
  exportExcel(className, title) {
    let xlsxParam = { raw: true }
    let wb = XLSX.utils.table_to_book(document.getElementById(className), xlsxParam);
    let wbout = XLSX.write(wb, {
      bookType: "xlsx",
      bookSST: true,
      type: "array"
    });
    try {
      FileSaver.saveAs(
        new Blob([wbout], { type: "application/octet-stream" }),
        title + ".xlsx"
      );
    } catch (e) {
      if (typeof console !== "undefined");
    }
    return wbout;
  },
  // 列表选中下载 excelData导出的数据,tHeader字段名称,filterVal字段
  downloadExcel(excelData, tHeader, filterVal) {
    require.ensure([], () => {
      let { export_json_to_excel } = require("@/components/excel/export2Excel");
      let data = excelData.map(v => filterVal.map(j => v[j]));
      // 这是表格的名称。合同列表+当前日期，dateFormatStr是一个方法，格式化了日期
      let excelName = '合同列表' + this.dateFormatStr(new Date)
      export_json_to_excel(tHeader, data, excelName); // 导出的表格名称，根据需要自己命名
    });
  },
  // 配置日期选择的快捷键
  datePickerOptions: {
    shortcuts: [
      {
        text: "今天",
        onClick(picker) {
          let end = new Date();
          let start = new Date();
          start.setHours(0);
          start.setMinutes(0);
          start.setSeconds(0);
          end.setHours(0);
          end.setMinutes(0);
          end.setSeconds(0);
          start.setTime(start.getTime());
          picker.$emit("pick", [start, end]);
        }
      },
      {
        text: "昨天",
        onClick(picker) {
          let end = new Date();
          let start = new Date();
          start.setDate(start.getDate() - 1);
          start.setHours(0);
          start.setMinutes(0);
          start.setSeconds(0);
          end.setDate(end.getDate() - 1);
          end.setHours(0);
          end.setMinutes(0);
          end.setSeconds(0);
          start.setTime(start.getTime());
          picker.$emit("pick", [start, end]);
        }
      },
      {
        text: "最近一周",
        onClick(picker) {
          let end = new Date();
          let start = new Date();
          start.setHours(0);
          start.setMinutes(0);
          start.setSeconds(0);
          end.setHours(0);
          end.setMinutes(0);
          end.setSeconds(0);
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
          picker.$emit("pick", [start, end]);
        }
      },
      {
        text: "最近一个月",
        onClick(picker) {
          let end = new Date();
          let start = new Date();
          start.setHours(0);
          start.setMinutes(0);
          start.setSeconds(0);
          end.setHours(0);
          end.setMinutes(0);
          end.setSeconds(0);
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
          picker.$emit("pick", [start, end]);
        }
      },
      {
        text: "最近三个月",
        onClick(picker) {
          let end = new Date();
          let start = new Date();
          start.setHours(0);
          start.setMinutes(0);
          start.setSeconds(0);
          end.setHours(0);
          end.setMinutes(0);
          end.setSeconds(0);
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
          picker.$emit("pick", [start, end]);
        }
      }
    ]
  },
  // 存放所有的平台.数据
  platformList: [
  ],
  //客户推广渠道
  channelList: [

    {
      Label: "主动电访"
    },
    {
      Label: "微信开发"
    },
    {
      Label: "QQ开发"
    },
    {
      Label: "转介绍"
    },
    {
      Label: "地推客户"
    },
    {
      Label: "合作客户"
    },
    {
      Label: "网销分配"
    },
    {
      Label: "百度移动"
    },
    {
      Label: "今日头条"
    },
    {
      Label: "抖音推广"
    },
    {
      Label: "百度PC"
    },
    {
      Label: "其他渠道"
    }
  ],

  //意向客户客户类型
  IntentionalCustomerType: [
    {
      value: -1,
      Label: "全部客户"
    },
    {
      value: 0,
      Label: "普通客户"
    },
    {
      value: 1,
      Label: "精准意向"
    },
    {
      value: 2,
      Label: "中等意向"
    },

    {
      value: 3,
      Label: "潜在意向"
    },
    {
      value: 4,
      Label: "线下签单"
    },
    {
      value: 5,
      Label: "暂无需求"
    },
    {
      value: 6,
      Label: "公海学员"
    },
  ],
  // 客户签订合同-层次类别
  costomSignUpLevel: [
    {
      value: 0,
      Label: "高起专"
    },
    {
      value: 1,
      Label: "专升本"
    },
    {
      value: 2,
      Label: "全日制专升本"
    },
    {
      value: 3,
      Label: "本升硕(研究生)"
    }
  ],
  // 客户签订合同-学历性质
  costomAcademicQualification: [
    {
      value: 0,
      Label: "应用型自考"
    },
    {
      value: 1,
      Label: "社会型自考"
    },
    {
      value: 2,
      Label: "网络教育"
    },
    {
      value: 3,
      Label: "成人高考"
    },
    {
      value: 4,
      Label: "国开(电大)"
    },
    {
      value: 5,
      Label: "全日制升本"
    },
    {
      value: 6,
      Label: "硕士研究生"
    }
  ],
  // 客户签订合同- 优惠类型
  costomPreferentialType: [
    {
      value: 0,
      Label: "优惠券"
    },
    {
      value: 1,
      Label: "活动优惠"
    },
    {
      value: 2,
      Label: "特殊申请优惠"
    }
  ],
  // 客户签订合同- 支付方式
  costomPaymentMethod: [
    {
      value: 0,
      Label: "微信支付"
    },
    {
      value: 1,
      Label: "支付宝支付"
    },
    {
      value: 2,
      Label: "对公转账"
    },
    {
      value: 3,
      Label: "百度分期"
    },
    {
      value: 4,
      Label: "小雨花分期"
    },
    {
      value: 6,
      Label: "分付君分期"
    },
    {
      value: 7,
      Label: "鸿学金信分期"
    },
    {
      value: 5,
      Label: "pos机刷卡"
    }
  ],
  //管理人员的身份列表
  managerRoleList: [
    {
      value: -1,
      Label: "全部"
    },
    {
      value: 0,
      Label: "老师"
    },
    {
      value: 1,
      Label: "管理员"
    },
    {
      value: 2,
      Label: "工作员"
    }
  ],
  // 授课形式
  teachingForm: [
    {
      value: 1,
      Label: "面授周末班"
    },
    {
      value: 2,
      Label: "面授工作日班"
    },
    {
      value: 3,
      Label: "面授晚班"
    },
    {
      value: 4,
      Label: "在线直播班"
    },
    {
      value: 5,
      Label: "在线录播班"
    },
    {
      value: 6,
      Label: "一对一VIP班"
    },
    {
      value: 7,
      Label: "其他类型"
    }
  ],
  collegeWithCouseKindList: [],//所有学院以及学院所带的课程大类
  courseKindList: [],//所有的课程大类 
  AllUniversity: [],//所有的高校列表  
  AllQuestionTypes: [],//所有题的类型  
  // 根据类型变化返回一些数据的Label
  FormatSelect(options, typeId) {
    let title = '未知'
    options.forEach(item => {
      if (item.Id == typeId) {
        title = item.Label
        return
      } else if (item.value == typeId) {
        title = item.Label
        return
      } else if (item.ID == typeId) {
        title = item.Label
        return
      }
    });
    return title
  }
}